Skip to content

compiler: Do not CSE-capture IndexedPointer indices - #3047

Closed
ggorman wants to merge 1 commit into
mainfrom
fix-cse-indexedpointer
Closed

ggorman wants to merge 1 commit into
mainfrom
fix-cse-indexedpointer

Conversation

@ggorman

@ggorman ggorman commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

IndexedPointer (ptr->field[idx]) had no handler in CSE's _catch, so the generic handler recursed into its index. When an integer index expression repeats inside a floating-point Cluster, CSE binds it to a CTemp, and cse_dtype promotes an integer expression in a float Cluster to the Cluster's float type. The result is a floating-point array subscript:

float r4 = (time / ct0f) + static_cast<int>(time >= 3)*static_cast<int>((3)%(ct0f) != 0);
f_vec->sizes[r4] = f_vec->sizes[r4];   // nvcc: expression must have integral or unscoped enum type
                                        // hipcc: array subscript is not an integer

This surfaced after #3043: the CondEq snapshot shift turned a bare IntDiv index (never captured) into an Add that CSE does capture. Any backend that lowers metadata lookups to IndexedPointer inside a float Cluster hits it.

Fix

Register IndexedPointer with the same _catch handler as Indexed/Symbol/Reserved, so CSE treats it as an opaque terminal and never looks inside its index. Two executable lines; no change to cse_dtype, whose promotion rule affects unrelated arithmetic.

Test

tests/test_cse.py::test_indexedpointer_index_not_captured: two IndexedPointers sharing a repeated integer index in a float32 Cluster; asserts no CTemp ends up inside an IndexedPointer index.

  • Negative control: with devito/passes/clusters/cse.py reverted the test fails (assert not True: the index was captured); with the change it passes.
  • tests/test_cse.py, test_dse.py, test_buffering.py: 306 passed, 2 xfailed (one MPI test fails identically without this change on the host used, due to a missing mpirun).
  • Generated CUDA source compiled with nvcc 12.4: 5 errors before, 0 after; the same case runs on an RTX 3090 (CUDA 12.9).

🤖 Generated with Claude Code


CI note. pytest-osx-py312-clang-omp-base fails on this PR for a reason unrelated to the change: the runner it drew is a non-M1 Apple chip, which get_platform() does not classify as AppleArm, so test_nested_nthreads is not skipped and emits x86 intrinsics headers. Fixed in #3048. pytest-gpu-omp-amd segfaults in the examples step (test_tti_stability[staggered]); the generated code for that operator is byte-identical with and without this change, and a concurrent unrelated PR run failed the same job (runner contention, tracked in #3049).

An IndexedPointer (`ptr->field[idx]`) had no handler in CSE's `_catch`, so
the generic handler recursed into its index. In a floating-point Cluster a
repeated integer index expression was then bound to a CTemp whose dtype
`cse_dtype` promotes to the Cluster's float type, producing an array
subscript of floating-point type that nvcc/hipcc reject.

Treat IndexedPointer like Indexed: an opaque terminal that CSE does not
look inside. Add a regression test that fails without this change.
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.15%. Comparing base (a9964bb) to head (5c8ec26).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3047      +/-   ##
==========================================
- Coverage   84.26%   84.15%   -0.12%     
==========================================
  Files         258      258              
  Lines       56982    56999      +17     
  Branches     4854     4856       +2     
==========================================
- Hits        48018    47967      -51     
- Misses       8138     8202      +64     
- Partials      826      830       +4     
Flag Coverage Δ
pytest-gpu-aomp-amdgpuX 68.56% <100.00%> (-0.01%) ⬇️
pytest-gpu-gcc- 79.04% <100.00%> (+0.01%) ⬆️
pytest-gpu-icx- 79.00% <100.00%> (+<0.01%) ⬆️
pytest-gpu-nvc-nvidiaX 69.14% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@FabioLuporini

FabioLuporini commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

thanks

closing since @mloubout has already cherry-picked this commit inside #3050 so we'll merge it via that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler no-pro-trigger Skip the devitopro submodule update on merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants